<template>
  <!--折线图-->
  <div
    :style="{width:width,height:height}"
  ></div>
</template>

<script>
  export default {
    name: 'PieChart',
    props: {
      width: {
        type: String,
        default: '100%'
      },
      height: {
        type: String,
        default: '100%'
      },
      /**
       * @param:
       *    dataLine  --> 数据
       * @date 2020/08/23
       * @author ZhuHongWei
       */
      chartData: {
        type: Number,
        default: 0
      },
      barColor: {
        type: String,
        default: '#58A3F7'
      }
    },
    data() {
      return {}
    },
    watch: {
      chartData: {
        deep: true,
        handler: function() {
          this.initChart()
        }
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.initChart()
      })
    },
    methods: {
      initChart() {
        this.chart = this.$echarts.init(this.$el)
        this.chart.clear()
        let option = {
          title: {
            text: this.chartData + '%',
            x: 'center',
            y: 'center',
            textStyle: {
              fontWeight: 'normal',
              color: '#fff',
              fontSize: '20'
            }
          },
          color: ['#282c40'],
          tooltip: {
            trigger: "item"
          },
          grid: {
            left: '0%',
            right: '0%',
            bottom: '0%',
            top: '0%'
          },
          series: [{
            name: '质差用户数比例',
            type: 'pie',
            radius: ['70%', '100%'],
            hoverAnimation: false,
            itemStyle: {
              normal: {
                label: {
                  show: false
                },
                labelLine: {
                  show: false
                }
              }
            },
            data: [{
              value: this.chartData,
              itemStyle: {
                normal: {
                  color: { // 完成的圆环的颜色
                    colorStops:  [{
                      offset: 0,
                      color: '#02d6fc' // 0% 处的颜色
                    }, {
                      offset: 1,
                      color: '#367bec' // 100% 处的颜色
                    }]
                  },
                  label: {
                    show: false
                  },
                  labelLine: {
                    show: false
                  }
                }
              }
            },
              {
                name: '',
                value: 100 - this.chartData
              }],
          }]
        }
        this.chart.setOption(option)
      }
    }
  }
</script>

<style scoped>
</style>
